********************************************************************************
* 8. Different cut-offs. Tables.
********************************************************************************
estimates clear
{
cap erase TABLES/TableB1_McCrary_cutoffs.txt

foreach c in 15 18 22 {

use DTA/Datos_ENIA_95_07_Processed.dta, clear

drop if abs(totmuj-`c')>10
gen n = 1
gen above           = totmuj>=`c'
forvalues i = 1/9 {
gen totmuj`i'         = (totmuj-`c')^`i'
gen totmuj`i'_above   = (totmuj-`c')^`i'*above
}

global Polinomio totmuj1 totmuj2 totmuj1_above totmuj2_above above

********************************************************************************

* Full sample:
preserve
collapse (sum) n, by($Polinomio)
gen log_n = log(n)
reg log_n $Polinomio
estimates store all
restore

* By Period:
preserve
collapse (sum) n, by($Polinomio period)
gen log_n = log(n)
reg log_n $Polinomio if period==1
estimates store early
reg log_n $Polinomio if period==2
estimates store midperiod
reg log_n $Polinomio if period==3
estimates store late
restore

* Sectors:
preserve
collapse (sum) n, by($Polinomio sectorA)
gen log_n = log(n)
reg log_n $Polinomio if sectorA==1
estimates store sectorA
reg log_n $Polinomio if sectorA==0
estimates store sectorB
restore

* Business Size:
preserve
collapse (sum) n, by($Polinomio large)
gen log_n = log(n)
reg log_n $Polinomio if large==0
estimates store small
reg log_n $Polinomio if large==1
estimates store large
restore

estout * using TABLES/TableB1_McCrary_cutoffs.txt, keep(above) stats( r2 rmse N , fmt(%9.3f %9.3f %9.0gc)) cells(b(fmt(%9.3f) star) se(par fmt(%9.3f)) ) starlevels (* 0.10 ** 0.05 *** 0.01 ) append style(tex) notype mlabels(, numbers )

}

********************************************************************************

********************************************************************************

********************************************************************************

* Using males in the cutoff:

estimates clear

use DTA/Datos_ENIA_95_07_Processed.dta, clear

drop if abs(tothom-20)>10
gen n = 1
gen above           = tothom>=20
forvalues i = 1/9 {
gen totmuj`i'         = (tothom-20)^`i'
gen totmuj`i'_above   = (tothom-20)^`i'*above
}

global Polinomio totmuj1 totmuj2 totmuj1_above totmuj2_above above

********************************************************************************

* Full sample:
preserve
collapse (sum) n, by($Polinomio)
gen log_n = log(n)
reg log_n $Polinomio
estimates store all
restore

* By Period:
preserve
collapse (sum) n, by($Polinomio period)
gen log_n = log(n)
reg log_n $Polinomio if period==1
estimates store early
reg log_n $Polinomio if period==2
estimates store midperiod
reg log_n $Polinomio if period==3
estimates store late
restore

* Sectors:
preserve
collapse (sum) n, by($Polinomio sectorA)
gen log_n = log(n)
reg log_n $Polinomio if sectorA==1
estimates store sectorA
reg log_n $Polinomio if sectorA==0
estimates store sectorB
restore

* Business Size:
preserve
collapse (sum) n, by($Polinomio large)
gen log_n = log(n)
reg log_n $Polinomio if large==0
estimates store small
reg log_n $Polinomio if large==1
estimates store large
restore

estout * using TABLES/TableB1_McCrary_cutoffs.txt, keep(above) stats( r2 rmse N , fmt(%9.3f %9.3f %9.0gc)) cells(b(fmt(%9.3f) star) se(par fmt(%9.3f)) ) starlevels (* 0.10 ** 0.05 *** 0.01 ) append style(tex) notype mlabels(, numbers )



********************************************************************************

********************************************************************************

********************************************************************************

* Using total workers to check if discontinuity around discrimination law:

estimates clear

use DTA/Datos_ENIA_95_07_Processed.dta, clear

drop if abs(tottrab-50)>10
gen n = 1
gen above           = tottrab>=50
forvalues i = 1/9 {
gen totmuj`i'         = (tottrab-50)^`i'
gen totmuj`i'_above   = (tottrab-50)^`i'*above
}

global Polinomio totmuj1 totmuj2 totmuj1_above totmuj2_above above

********************************************************************************

* Full sample:
preserve
collapse (sum) n, by($Polinomio)
gen log_n = log(n)
reg log_n $Polinomio
estimates store all
restore

* By Period:
preserve
collapse (sum) n, by($Polinomio period)
gen log_n = log(n)
reg log_n $Polinomio if period==1
estimates store early
reg log_n $Polinomio if period==2
estimates store midperiod
reg log_n $Polinomio if period==3
estimates store late
restore

* Sectors:
preserve
collapse (sum) n, by($Polinomio sectorA)
gen log_n = log(n)
reg log_n $Polinomio if sectorA==1
estimates store sectorA
reg log_n $Polinomio if sectorA==0
estimates store sectorB
restore

estout * using TABLES/TableB1_McCrary_cutoffs.txt, keep(above) stats( r2 rmse N , fmt(%9.3f %9.3f %9.0gc)) cells(b(fmt(%9.3f) star) se(par fmt(%9.3f)) ) starlevels (* 0.10 ** 0.05 *** 0.01 ) append style(tex) notype mlabels(, numbers )

***********************************************************************************************************************************
estimates clear

use DTA/Datos_ENIA_95_07_Processed.dta, clear

drop if abs(tottrab-200)>10
gen n = 1
gen above           = tottrab>=200
forvalues i = 1/9 {
gen totmuj`i'         = (tottrab-200)^`i'
gen totmuj`i'_above   = (tottrab-200)^`i'*above
}

global Polinomio totmuj1 totmuj2 totmuj1_above totmuj2_above above

********************************************************************************

* Full sample:
preserve
collapse (sum) n, by($Polinomio)
gen log_n = log(n)
reg log_n $Polinomio
estimates store all
restore

* By Period:
preserve
collapse (sum) n, by($Polinomio period)
gen log_n = log(n)
reg log_n $Polinomio if period==1
estimates store early
reg log_n $Polinomio if period==2
estimates store midperiod
reg log_n $Polinomio if period==3
estimates store late
restore

* Sectors:
preserve
collapse (sum) n, by($Polinomio sectorA)
gen log_n = log(n)
reg log_n $Polinomio if sectorA==1
estimates store sectorA
reg log_n $Polinomio if sectorA==0
estimates store sectorB
restore

estout * using TABLES/TableB1_McCrary_cutoffs.txt, keep(above) stats( r2 rmse N , fmt(%9.3f %9.3f %9.0gc)) cells(b(fmt(%9.3f) star) se(par fmt(%9.3f)) ) starlevels (* 0.10 ** 0.05 *** 0.01 ) append style(tex) notype mlabels(, numbers )


********************************************************************************

********************************************************************************

********************************************************************************

* Using total workers to check if discontinuity around discrimination law:

estimates clear

use DTA/Datos_ENIA_95_07_Processed.dta, clear

gen frac_muj=round(totmuj/tottrab,0.01)

drop if abs(frac_muj-0.1)>0.1
gen n = 1
gen above           = frac_muj>=0.1
forvalues i = 1/9 {
gen totmuj`i'         = (frac_muj-0.1)^`i'
gen totmuj`i'_above   = (frac_muj-0.1)^`i'*above
}

global Polinomio totmuj1 totmuj2 totmuj1_above totmuj2_above above

********************************************************************************

* Full sample:
preserve
collapse (sum) n, by($Polinomio)
gen log_n = log(n)
reg log_n $Polinomio
estimates store all
restore

* By Period:
preserve
collapse (sum) n, by($Polinomio period)
gen log_n = log(n)
reg log_n $Polinomio if period==1
estimates store early
reg log_n $Polinomio if period==2
estimates store midperiod
reg log_n $Polinomio if period==3
estimates store late
restore

* Sectors:
preserve
collapse (sum) n, by($Polinomio sectorA)
gen log_n = log(n)
reg log_n $Polinomio if sectorA==1
estimates store sectorA
reg log_n $Polinomio if sectorA==0
estimates store sectorB
restore

* Business Size:
preserve
collapse (sum) n, by($Polinomio large)
gen log_n = log(n)
reg log_n $Polinomio if large==0
estimates store small
reg log_n $Polinomio if large==1
estimates store large
restore

estout * using TABLES/TableB1_McCrary_cutoffs.txt, keep(above) stats( r2 rmse N , fmt(%9.3f %9.3f %9.0gc)) cells(b(fmt(%9.3f) star) se(par fmt(%9.3f)) ) starlevels (* 0.10 ** 0.05 *** 0.01 ) append style(tex) notype mlabels(, numbers )


**********************************************************************************************
*********************************************************************************************

estimates clear

use DTA/Datos_ENIA_95_07_Processed.dta, clear

gen frac_muj=round(totmuj/tottrab,0.01)

drop if abs(frac_muj-0.2)>0.1
gen n = 1
gen above           = frac_muj>=0.2
forvalues i = 1/9 {
gen totmuj`i'         = (frac_muj-0.2)^`i'
gen totmuj`i'_above   = (frac_muj-0.2)^`i'*above
}

global Polinomio totmuj1 totmuj2 totmuj1_above totmuj2_above above

********************************************************************************

* Full sample:
preserve
collapse (sum) n, by($Polinomio)
gen log_n = log(n)
reg log_n $Polinomio
estimates store all
restore

* By Period:
preserve
collapse (sum) n, by($Polinomio period)
gen log_n = log(n)
reg log_n $Polinomio if period==1
estimates store early
reg log_n $Polinomio if period==2
estimates store midperiod
reg log_n $Polinomio if period==3
estimates store late
restore

* Sectors:
preserve
collapse (sum) n, by($Polinomio sectorA)
gen log_n = log(n)
reg log_n $Polinomio if sectorA==1
estimates store sectorA
reg log_n $Polinomio if sectorA==0
estimates store sectorB
restore

* Business Size:
preserve
collapse (sum) n, by($Polinomio large)
gen log_n = log(n)
reg log_n $Polinomio if large==0
estimates store small
reg log_n $Polinomio if large==1
estimates store large
restore

estout * using TABLES/TableB1_McCrary_cutoffs.txt, keep(above) stats( r2 rmse N , fmt(%9.3f %9.3f %9.0gc)) cells(b(fmt(%9.3f) star) se(par fmt(%9.3f)) ) starlevels (* 0.10 ** 0.05 *** 0.01 ) append style(tex) notype mlabels(, numbers )

}
